﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BBPA.Admin.SYS.ApplyDraw
{
    public partial class FormState : FormPage
    {
        BLL.Draw bll = new BLL.Draw();
        Model.Draw model = new Model.Draw();
        //
        protected void Page_Load(object sender, EventArgs e) {}
        /// <summary>
        /// 初始化本页Model
        /// </summary>
        public override void Page_Load_DefaultModel()
        {
            model = bll.GetModel(Master.id);
        }
        /// <summary>
        /// 初始化表单
        /// </summary>
        public override void Form_Default()
        {
            rbl_State.Items.Add(new ListItem(EnumHelper.GetEnumDescription(EnumHelper.DrawState.Agree), ((int)EnumHelper.DrawState.Agree).ToString()));
            rbl_State.Items.Add(new ListItem(EnumHelper.GetEnumDescription(EnumHelper.DrawState.NotAgree), ((int)EnumHelper.DrawState.NotAgree).ToString()));
            rbl_State.SelectedIndex = 0;
            lb_Money.Text = StringPlus.showMoney(model.Money);
        }
        /// <summary>
        /// 绑定表单数据【修改时用】
        /// </summary>
        public override void Form_Bind()
        {
        }
        /// <summary>
        /// 提交
        /// </summary>
        public override void Form_Submit()
        {
            model.State = DataTypePlus.requestInt(rbl_State.SelectedValue);
            model.Description = tb_Description.Text;
            model.DateandtimeFinish = DateTime.Now;
            bll.Update(model);
            BLL.User_Operate_Log.Add(Security.GetCurrentUserID(), EnumHelper.TableName.Draw, Master.id, EnumHelper.OperateType.Update,"处理提款申请："+ rbl_State.SelectedItem.Text);
            CallBak<int> callBak = 
                BLL.Account_Change_Log.Add(model.StoreID > 0 ? EnumHelper.UserType.Store : EnumHelper.UserType.Supplier, model.StoreID + model.SupplierID,
                model.State==(int)EnumHelper.DrawState.Agree?EnumHelper.AccountChangeReason.Agree_ApplyDraw:EnumHelper.AccountChangeReason.NotAgree_ApplyDraw, Master.id, model.Money);
            if (!callBak.IsSuccess) Master.ScriptManager_Alert_float(callBak.ErrMsg, false);
            else
            {
                BLL.User_Operate_Log.Add(Security.GetCurrentUserID(), EnumHelper.TableName.Account_Change_Log, callBak.ReturnVal, EnumHelper.OperateType.Add, "处理提款申请:" + callBak.ErrMsg);
                Master.SubmitOK();
            }      
        }

        protected void rbl_State_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectState = DataTypePlus.requestInt(rbl_State.SelectedValue);
            if (selectState == (int)EnumHelper.DrawState.Agree) group_Description.Visible = false;
            else group_Description.Visible = true;
        }
    }
}